/*
 * Copyright (C) 2009 M. Hautle.
 * 
 * This file is part of TrackedBean.
 * 
 * TrackedBean is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General
 * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
 * later version.
 * 
 * TrackedBean is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Lesser General Public License along with TrackedBean. If not, see
 * <http://www.gnu.org/licenses/>.
 */
package ch.trackedbean.binding.guicomponents.lists;

import java.awt.*;
import java.util.List;
import ch.trackedbean.binding.guicomponents.action.*;
import ch.trackedbean.binding.mapping.*;

/**
 * Interface describing an adapter for a list holding element.<br>
 * You may map the adapter using {@link MappingGroup#createListAdapterBinding(String, IListAdapter)}.
 * 
 * @author M. Hautle
 * @param <T> The adapted component
 * @param <C> The list content type
 */
public interface IListAdapter<T extends Component, C> extends ICleanUp {
	/**
	 * Retruns the adapted component.
	 * 
	 * @return The adapted component
	 */
	T getComponent();

	/**
	 * Returns a list holding the selected elements.
	 * 
	 * @return The selected elements
	 */
	List<C> getSelection();

	/**
	 * Returns a the selected indices in icreasing order.
	 * 
	 * @return The selected indices
	 */
	int[] getSelectedIndices();

	/**
	 * Returns the list representing the model.<br>
	 * This method simply returns the list set by {@link #setModel(List)}.<br>
	 * This method may be implemented or may just return null.
	 * 
	 * @return The model or null
	 */
	List<C> getModel();

	/**
	 * Sets a reference to the list representing the model of the adapted component.<br>
	 * The model set by this method can be retrived using {@link #getModel()}.<br>
	 * This method may be implemented or may just do nothing.
	 * 
	 * @param model The reference to the model or null
	 */
	void setModel(List<C> model);

	/**
	 * Adds the given action and calls {@link ISelectionAction#selectionChanged(List)} using the current selection.
	 * 
	 * @param action Adds the given action
	 */
	void addAction(ISelectionAction<C> action);

	/**
	 * Removes the given action.
	 * 
	 * @param action Removes the given action
	 */
	public void removeAction(ISelectionAction<C> action);

	/**
	 * "Destroyes" the adapter by freeing it's ressources and detaching it's internal listeners
	 */
	void dispose();
}